import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

/*
 * 适配Android状态栏背景和状态栏字体颜色
 */
class StateBarLessWidget extends StatelessWidget {
  final bool stateBarTextColor; //状态栏字体颜色
  final Color systemNavigationBarColor; //状态栏底部按键背景颜色
  final Widget child; //子控件
  final PreferredSizeWidget appBar; //AppBar,Scaffold自带参数
  final Widget floatingActionButton; //右下键Button，Scaffold自带参数
  final Key key;

  StateBarLessWidget(
      {this.key,
      this.stateBarTextColor = true,
      this.systemNavigationBarColor = Colors.transparent,
      @required this.child,
      this.appBar,
      this.floatingActionButton});

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion(
      key: key,
      child: Scaffold(
        appBar: appBar,
        body: child,
        floatingActionButton: floatingActionButton,
      ),
      value: (stateBarTextColor
              ? SystemUiOverlayStyle.light
              : SystemUiOverlayStyle.dark)
          .copyWith(systemNavigationBarColor: systemNavigationBarColor)
          .copyWith(statusBarColor: systemNavigationBarColor),
    );
  }
}
